<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app {
            width: 700px;
            margin: 10px auto;
        }

        .tb {
            border-collapse: collapse;
            width: 100%;
        }

        .tb th {
            color: rgb(16, 15, 15);
        }

        .tb td,
        .tb th {
            padding: 5px;
            border: 1px solid black;
            text-align: center;
        }

        .add {
            padding: 5px;
            border: 1px solid black;
            margin-bottom: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <table class="tb">
            <tr>
                <td>欢迎光临—vue开发的收银系统-水果店</td>
            </tr>
            <tr>
                <th>苹果 10 ￥/斤，折扣<8折>
                </th>
            </tr>
            <tr>
                <td>请输入你要购买的斤数<input v-model.number="weight" type="text"></td>
            </tr>
            <tr>
                <td><button @click="calculatePrice">结账买单~</button></td>
            </tr>
            <tr>
                <td>结账单:总价:{{totalPrice}}￥元 折后价:{{discountedPrice }}￥元 省了:{{savedAmount}}￥元</td>
            </tr>
        </table>
    </div>
    <script src="./vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                weight: 0,
                totalPrice: 0,
                discountedPrice: 0,
                savedAmount: 0
            },
            methods: {
                calculatePrice(){
                    const pricePerJin = 10; // 苹果的价格，10元/斤
                    const discount = 0.8; // 折扣，8折

                    this.totalPrice = this.weight * pricePerJin;
                    this.discountedPrice = this.totalPrice * discount;
                    this.savedAmount = this.totalPrice - this.discountedPrice;
                }
            }
        })
    </script>

</body>

</html>